package city.yueyang.system.api;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import city.yueyang.common.core.constant.SecurityConstants;
import city.yueyang.common.core.constant.ServiceNameConstants;
import city.yueyang.common.core.domain.R;
import city.yueyang.system.api.domain.SysUser;
import city.yueyang.system.api.factory.RemoteUserFallbackFactory;
import city.yueyang.system.api.model.LoginUser;

/**
 * 用户服务
 *
 * @author XiaoHH
 */
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, path = "/user", fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService {
    /**
     * 通过用户名查询用户信息
     *
     * @param username 用户名
     * @param source   请求来源
     * @return 结果
     */
    @GetMapping("/info/{username}")
    R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 注册用户信息
     *
     * @param sysUser 用户信息
     * @param source  请求来源
     * @return 结果
     */
    @PostMapping("/register")
    R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 根据用户id判断是否为超级管理员
     *
     * @param userId 用户id
     * @return 判断结果
     */
    @GetMapping("/admin/{userId}")
    R<Boolean> isAdmin(@PathVariable("userId") Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 判断是否能够注册
     *
     * @param source 内部调用参数
     * @return 判断结果
     */
    @GetMapping("/register")
    R<Boolean> canRegister(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}
